package com.ccjq.shosestore.web.controller.product;

import com.ccjq.shosestore.core.domain.PageInfo;
import com.ccjq.shosestore.product.po.HomePo;
import com.ccjq.shosestore.product.service.impl.HomeServiceImpl;
import com.ccjq.shosestore.product.t_productPo.productPo;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 产品控制器
 */
public class ProductServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PageInfo<productPo> pageInfo = null;
        int pageSizes = 0;
        int pageNos = 0;
        String categoryId = request.getParameter("categoryId");
        String pageSize   = request.getParameter("pageSize");//每页显示的行数
        String pageNo     = request.getParameter("pageNo"); //当前页
        HomeServiceImpl  hsi = new HomeServiceImpl();
        if( StringUtils.isBlank(pageSize)){
            pageSizes=6;
        }else {
            pageSizes =Integer.parseInt(pageSize);
        }
        if(StringUtils.isBlank(pageNo)){
            pageNos=1;
        }else {
            pageNos = Integer.parseInt(pageNo);
        }
        if(StringUtils.isBlank(categoryId)){
            pageInfo = hsi.selectFengYeAll(pageSizes,pageNos);
        }else {
            pageInfo = hsi.selectFengYe(categoryId,pageSizes,pageNos);
        }
        List<productPo> listCar = pageInfo.getObjs();
        List<HomePo> homeList = hsi.selectAll();
        request.setAttribute("pageInfo",pageInfo);
        request.setAttribute("listCar",listCar);
        request.setAttribute("homeList",homeList);
        request.setAttribute("category_id",categoryId);
        request.getRequestDispatcher("/WEB-INF/jsp/product/product_list.jsp").forward(request,response);

    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
